package kr.hkit.androidcomplete02.service;

import kr.hkit.androidcomplete02.R;
import android.app.Service;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;

public class MusicService extends Service { 
	
	private static final String TAG = "MusicService";
	MediaPlayer player;

	@Override
	public IBinder onBind(Intent intent) { //이건 원격지호출용
		return null;
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
		Log.d(TAG, "onCreate()");
		player = MediaPlayer.create(this, R.raw.music);
		player.setLooping(false); //반복안함
	}
	
	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		Log.d(TAG, "onStartCommand()");
		Toast.makeText(this, "Music Service가 시작되었습니다.", Toast.LENGTH_LONG).show();
		player.start();
		return super.onStartCommand(intent, flags, startId);
	}


	@Override
	public void onDestroy() {
		super.onDestroy();
		Log.d(TAG, "onDestroy()");
		Toast.makeText(this, "Music Service가 중지되었습니다.", Toast.LENGTH_LONG).show();
		player.stop();
	}

}
